let requests = require('requests');
let fs = require('fs') //fs模块
let path = require('path') //path模块
requests('https://www.jsdaima.com/Uploads/js/201803/1522376449/js/rollslide.js')
    // 1. https://www.jsdaima.com/js/demo/1358.html  // 爬取首页
    // 2. https://www.jsdaima.com/Uploads/js/201803/1522376449/css/demo.css  //爬取css
    // 3. https://www.jsdaima.com/Uploads/js/201803/1522376449/js/rollslide.js  //爬取js
    .on('data', function(chunk) {
        console.log(chunk)
        fs.writeFile(path.resolve(__dirname, 'rollslide.js'), chunk, () => {
            // 1.path.resolve(__dirname, 'index.html')  // 爬取首页
            // 2.path.resolve(__dirname, 'demo.css')   //爬取css
            // 3.path.resolve(__dirname, 'rollslide.js')  //爬取js
            console.log('保存成功');

        })
    })

/* 
爬取成功后把路径改成同级目录，即可打开

index.html
    <link rel="stylesheet" href="css/demo.css" />   //原来
    <link rel="stylesheet" href="demo.css" />       //现在

    <script src="js/rollslide.js"></script> //原来
    <script src="rollslide.js"></script>    //现在
    
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> //引入jQuery
*/